<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no">
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        .canvas {
            border: 1px solid black;
        }
    </style>
</head>
<body>
<div class="content_body">
    <canvas class="canvas" width="700px" height="400px"></canvas>
</div>
<script>
    let canvas = document.getElementsByClassName("canvas")[0];
    let ctx = canvas.getContext('2d');
    // 绘制图片的三种方式
     let img=new Image();
     img.onload=function () {
         // ctx.drawImage(img,1,245,150,150)

         // 9个参数
         // x1,y1,w1,h1:画布中的一个矩形区域
         // 400,410:图片上定位的坐标
         // 400,420：图片截取的区域
         // 100,100：x轴，y轴坐标
         // 250,250：图片大小
         ctx.drawImage(img,400,410,400,420,100,100,250,250)
     };
     img.src='1.jpg';
</script>
</body>
</html>